package com.zmn.oms.common.constant;

import lombok.Data;

/**
 * 类描述：
 *
 * 状态码格式说明：
 *  2 1 1 01
 *  | | | |---- 具体业务编号
 *  | | |------ 流程中某个阶段的编号
 *  | |-------- 涉及业务类型：1：订单； 2：投诉
 *  |---------- 数据走向：1：第三方（甲方） --> 啄木鸟； 2：啄木鸟 --> 第三方（甲方）
 *
 * @author lhl
 * @date 2020/06/29 16:52
 */
public final class TodmConsts {

    /**
     * 数据走向
     */
    public static final int DATA_IN = 1;
    public static final int DATA_OUT = 2;

    /**
     * 主动请求甲方
     */
    public static final class Out {
        /* ========= 同步状态 ======== */
        public static final int SYNC_TYPE_RECIVE = 21101;           // 回复收到订单
        public static final int SYNC_TYPE_ACCEPT_ORDER = 21102;     // 回复确认接单
        public static final int SYNC_TYPE_RUSH_ORDER = 21103;       // 抢单
        public static final int SYNC_TYPE_PULL_ORDER = 21104;       // 拉取订单
        public static final int SYNC_TYPE_CONFIRM = 21201;          // 确认订单
        public static final int SYNC_TYPE_DUTYTIME = 21202;         // 预约时间
        public static final int SYNC_TYPE_DISTRIBUTED = 21301;      // 派单给师傅
        public static final int SYNC_TYPE_VISITED = 21302;          // 师傅已上门
        public static final int SYNC_TYPE_MASTER_AMOUNT = 21303;    // 同步师傅收款额
        public static final int SYNC_TYPE_SECOND_PAY_AMOUNT = 21311;// 同步待补差价金额
        public static final int SYNC_TYPE_COMPLETE = 21501;         // 订单完成
        public static final int SYNC_TYPE_CANCEL = 21601;           // 订单取消
        public static final int SYNC_TYPE_REFUND_REPLY = 21610;     // 回复退款结果
        public static final int SYNC_TYPE_QUERY_ORDER_INFO = 21700; // 查询订单信息

        public static String getOperationName(Integer operation) {
            if (operation == null) {
                return null;
            }

            switch (operation.intValue()) {
                case SYNC_TYPE_RECIVE : return "回复收到订单";
                case SYNC_TYPE_ACCEPT_ORDER : return "回复确认接单";
                case SYNC_TYPE_RUSH_ORDER : return "抢单";
                case SYNC_TYPE_PULL_ORDER : return "拉取订单";
                case SYNC_TYPE_CONFIRM : return "确认订单";
                case SYNC_TYPE_DUTYTIME : return "预约时间";
                case SYNC_TYPE_DISTRIBUTED : return "派单给师傅";
                case SYNC_TYPE_VISITED : return "师傅已上门";
                case SYNC_TYPE_MASTER_AMOUNT : return "同步师傅收款额";
                case SYNC_TYPE_SECOND_PAY_AMOUNT : return "同步待补差价金额";
                case SYNC_TYPE_COMPLETE : return "订单完成";
                case SYNC_TYPE_CANCEL : return "订单取消";
                case SYNC_TYPE_REFUND_REPLY : return "回复退款结果";
                case SYNC_TYPE_QUERY_ORDER_INFO : return "查询订单信息";
                default: return null;
            }
        }
    }

    /**
     * 甲方请求数据
     */
    public static final class In {
        /* ========= 消息类型 ======== */
        public static final int MSG_NEW_OEDER = 11101;                  // 收到订单
        public static final int MSG_BILL_CHANGED = 11200;               // 金额变更
        public static final int MSG_PAY = 11201;                        // 支付
        public static final int MSG_SECOND_PAY = 11202;                 // 二次支付
        public static final int MSG_CHANGE_OREDER_STATUS = 11400;       // 修改订单状态
        public static final int MSG_CANCEL_OEDER = 11401;               // 取消订单
        public static final int MSG_OEDER_COMPLETE = 11501;             // 订单完成
        public static final int MSG_APPLY_REFUND = 11402;               // 申请退款
        public static final int MSG_CHANGE_SERVICE_TIME = 11403;        // 修改预约时间
        public static final int MSG_COMMENT = 11601;                    // 评价
        public static final int MSG_OTHER = 11900;                      // 其他消息


        public static String getOperationName(Integer operation) {
            if (operation == null) {
                return null;
            }

            switch (operation.intValue()) {
                case MSG_NEW_OEDER : return "收到订单";
                case MSG_BILL_CHANGED : return "金额变更";
                case MSG_PAY : return "支付";
                case MSG_SECOND_PAY : return "二次支付";
                case MSG_CHANGE_OREDER_STATUS : return "修改订单状态";
                case MSG_CANCEL_OEDER : return "取消订单";
                case MSG_OEDER_COMPLETE : return "订单完成";
                case MSG_APPLY_REFUND : return "申请退款";
                case MSG_CHANGE_SERVICE_TIME : return "修改预约时间";
                case MSG_COMMENT : return "评价";
                case MSG_OTHER : return "其他消息";
                default: return null;
            }
        }
    }


    public static DockingInfo getDockingInfo(Integer operation) {
        if (operation == null) {
            return null;
        }

        boolean isDataIn = operation.intValue() < 20000;

        String operationName = isDataIn ? In.getOperationName(operation) : Out.getOperationName(operation);
        if (operationName != null) {
            DockingInfo dockingInfo = isDataIn
                    ? new DockingInfo(DATA_IN, "[O] --> ZMN", operation, operationName)
                    : new DockingInfo(DATA_OUT, "ZMN --> [O]", operation, operationName);
            return dockingInfo;
        }

        return null;
    }

    @Data
    public static final class DockingInfo {
        private int type;
        private String typeIcon;
        private int operation;
        private String operationName;

        public DockingInfo(int type, String typeIcon, int operation, String operationName) {
            this.type = type;
            this.typeIcon = typeIcon;
            this.operation = operation;
            this.operationName = operationName;
        }
    }

    /**
     * 私有构造器，防止外部实例化
     */
    private TodmConsts() {}
}
